﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式之禅.装饰模式
{
    /// <summary>
    /// 抽象构件类
    /// </summary>
    public abstract class AbstractPhone
    {
        public abstract string Say();
    }
    /// <summary>
    /// 具体构件类角色
    /// </summary>
    public class ApplePhone : AbstractPhone
    {
        public override string Say()
        {
            return "ApplePhone";
        }
    }

    /// <summary>
    /// 抽象装饰类
    /// </summary>
    public abstract class AbstractDecorator : AbstractPhone
    {
        private AbstractPhone phone;
        public AbstractDecorator(AbstractPhone p)
        {
            this.phone = p;
        }

        public override string Say()
        {
            return phone.Say();
        }
    }
    /// <summary>
    /// 具体装饰类A
    /// </summary>
    public class DecoratorA : AbstractDecorator
    {
        public DecoratorA(AbstractPhone p)
            : base(p)
        {
        }

        public override string Say()
        {
            var r1 = base.Say();
            var r2 = this.DecoratorAMethod();
            return r1 + r2;
        }
        private string DecoratorAMethod()
        {
            return " DecoratorAAAAA Check.";
        }
    }
    /// <summary>
    /// 具体装饰类B
    /// </summary>
    public class DecoratorB : AbstractDecorator
    {
        public DecoratorB(AbstractPhone p)
            : base(p)
        {
        }

        public override string Say()
        {
            var r1 = base.Say();
            var r2 = this.DecoratorBMethod();
            return r2 + r1;
        }
        private string DecoratorBMethod()
        {
            return " DecoratorBBBB Check. ";
        }
    }

}
